home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / tests / setjmp / RCS / test.c,v < prev   
Encoding:
Text File  |  1992-07-17  |  859 b   |  70 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  srv030:1.1 srv027:1.1 srv026:1.1 srv024:1.1 srv021:1.1 srv018:1.1 srv014:1.1 srv010:1.1 srv008:1.1 srv007:1.1 srv006:1.1 srv004:1.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     92.03.12.20.54.53;  author kupfer;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @Simple test program for setjmp & longjmp.
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @/* 
  27.  * Test program to verify that setjmp and longjmp work.
  28.  */
  29.  
  30. #include <stdio.h>
  31. #include <setjmp.h>
  32.  
  33. jmp_buf env;
  34.  
  35. main()
  36. {
  37.     int ch;
  38.  
  39.     for (;;) {
  40.     if (setjmp(env)) {
  41.         printf("longjmp.\n");
  42.     }
  43.     printf("? ");
  44.     ch = getone();
  45.     if (ch == EOF) {
  46.         exit(0);
  47.     } else {
  48.         printf("%c\n", ch);
  49.     }
  50.     }
  51. }
  52.  
  53. getone()
  54. {
  55.     return getone_b();
  56. }
  57.  
  58. getone_b()
  59. {
  60.     int ch;
  61.  
  62.     ch = getchar();
  63.     if (ch == 'l') {
  64.     longjmp(env, 1);
  65.     } else {
  66.     return ch;
  67.     }
  68. }
  69. @
  70.